package com.mybank.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mybank.pojo.TransactionRecord;
import com.mybank.service.TransactionRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
@CrossOrigin
@RestController
@RequestMapping("/transactionRecord")
public class TransactionRecordController {
    @Autowired
    private TransactionRecordService transactionRecordService;
    @PostMapping
    public void save(@RequestBody TransactionRecord transactionRecord){
        transactionRecordService.save(transactionRecord);
    }
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id){
        transactionRecordService.removeById(id);
    }
    @PutMapping
    public void update(@RequestBody TransactionRecord transactionRecord){
        transactionRecordService.updateById(transactionRecord);
    }
    @GetMapping("/{id}")
    public TransactionRecord getById(@PathVariable Integer id){
        return transactionRecordService.getById(id);
    }
    @GetMapping
    public List<TransactionRecord> getAll(){
        return transactionRecordService.list();
    }

    /**
     * 按卡号分页查询交易记录
     * @param params 入参
     * @return 页面数据
     */
    @PostMapping("/page")
    public Page<TransactionRecord> getByPage(@RequestBody HashMap<String,String> params){
        return transactionRecordService.getPage(params);
    }
}
